<script setup lang="ts">
import { getMusicLyric, getMusicUrl } from "@/apis/music/player";
import { getRecommendMusicApi } from "@/apis/music/recommend";
import type { getRecommendMusicResultItem } from "@/types/recommend";
import { onBeforeMount, ref } from "vue";
import { useMusicStore } from "@/stores/music";
const store = useMusicStore();
const recommendMusicList = ref<getRecommendMusicResultItem[]>([]);
onBeforeMount(async () => {
  const res = await getRecommendMusicApi({ limit: 14 });
  recommendMusicList.value = res.data.result;
});
const playerMusic = async (id: number, picUrl: string) => {
  const res = await getMusicUrl({ id });
  const MusicLyric = await getMusicLyric({ id });
  store.musicData = res.data.data[0];
  store.isPlayer = !store.isPlayer;
  store.musicPicUrl = picUrl;
  store.getMusicLyric = MusicLyric.data.lrc.lyric;
};
const addMusicList = async (item: getRecommendMusicResultItem) => {
  // console.log(item);
  const res = await getMusicUrl({ id: item.id });
  const musicLyric = await getMusicLyric({ id: item.id });
  store.waitMusicLyric.push(musicLyric.data.lrc.lyric);
  store.waitPlayMusic.push(res.data.data[0]);
  store.waitMusicPic.push(item.picUrl);
  store.WaitMusicInfo.push(item);
};
</script>
<template>
  <div class="recommendMusic">
    <el-card style="max-width: 100%" shadow="always">
      <template #header>
        <div class="card-header">
          <span>推荐歌曲</span>
          <span class="moreList">更多>>></span>
        </div>
      </template>
      <div class="card-body">
        <div
          class="recommendMusicItem"
          v-for="item in recommendMusicList"
          :key="item.id"
        >
          <div class="playerMask">
            <el-icon
              size="60"
              color="red"
              @click="playerMusic(item.id, item.picUrl)"
              ><VideoPlay
            /></el-icon>
            <el-dropdown
              trigger="click"
              popper-class="recommendMusicSelect"
              @command="addMusicList(item)"
            >
              <el-icon size="20" color="red" class="moreSelect"
                ><More
              /></el-icon>
              <span class="el-dropdown-link"> </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>添加到播放列表</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
          <img :src="item.picUrl" alt="" />
          <p>{{ item.name }}</p>
        </div>
      </div>
    </el-card>
  </div>
</template>
<style scoped lang="scss">
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .moreList {
    font-size: 12px;
  }
}
.card-body {
  width: 100%;
  display: flex;
  justify-content: start;
  align-items: center;
  height: 100%;
  column-gap: 15px;
  flex-wrap: wrap;
  row-gap: 20px;
  .recommendMusicItem:hover {
    div.playerMask {
      //   top: 0px;
      opacity: 1;
    }
  }
  .recommendMusicItem {
    flex: 1;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    row-gap: 10px;
    position: relative;
    div.playerMask {
      width: 150px;
      height: 150px;
      border-radius: 10px;
      position: absolute;
      background-color: rgba($color: #000000, $alpha: 0.4);
      //   top: 150px;
      transition: all 0.2s linear;
      opacity: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      .el-dropdown {
        position: absolute;
        top: 10px;
        right: 10px;
      }
    }
    img {
      width: 150px;
      height: 150px;
      border-radius: 10px;
      box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    }
    p {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
      font-size: 14px;
    }
  }
}
</style>
